package com.sikadwafastdaisfondturbo.pretloan.adapter

import android.view.View
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.sikadwafastdaisfondturbo.lib_baseadapter.SikadwaRecyclerViewAdapter
import com.sikadwafastdaisfondturbo.lib_baseadapter.SikadwaViewHolderHelper
import com.sikadwafastdaisfondturbo.pretloan.R
import org.json.JSONObject

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2024/4/19 17:24
 * @Annotation：身份验证类型适配器
 */
class OcrTypeAdapter (recyclerView: RecyclerView?) : SikadwaRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_ocr_type) {

    override fun setItemChildListener(helper: SikadwaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }

    override fun fillData(helper: SikadwaViewHolderHelper, position: Int, model: JSONObject) {
        val isSelect = model.optBoolean("isSelect", false)
        val itemLayout = helper.getView<LinearLayout>(R.id.itemLayout)
        val imgView = helper.getImageView(R.id.imgView)
        val textTitle = helper.getTextView(R.id.textTitle)
        textTitle.text = model.optString("title")

        if (isSelect) {
            imgView.setImageResource(model.optInt("selectIconId"))
            textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.FF4C8FFB))
            itemLayout.setBackgroundResource(R.drawable.ocr_type_select)
            helper.setVisibility(R.id.imgSelect, View.VISIBLE)
        } else {
            imgView.setImageResource(model.optInt("normalIconId"))
            textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.FF999999))
            itemLayout.setBackgroundResource(R.drawable.radius_fill_ffffff_12)
            helper.setVisibility(R.id.imgSelect, View.INVISIBLE)
        }
    }
}